Skip to content

New BeanHas and BeanProperty matchers#3

Open
sandromancuso wants to merge 6 commits intohamcrest:masterfrom
sandromancuso:master
Open

New BeanHas and BeanProperty matchers#3
sandromancuso wants to merge 6 commits intohamcrest:masterfrom
sandromancuso:master

Conversation

@sandromancuso
Copy link
Copy Markdown

The idea is to be able to test multiple properties in a single assertion and get a decent error message when at least one of them does not match.

I've written these matchers and we use them in a few projects at work. We thought that it would be a good idea to contribute back to JavaHamcrest. I changed my original classes to so it would fit better the coding style used in JavaHamcrest, including the way the tests are written.

I know that Hamcrest has the allOf and hasProperty matchers. They are very good but I personally think that BeanHas and BeanProperty could be a good addition to the library since they work in a slightly different way.

For more details, I've blogged about the matchers here: http://craftedsw.blogspot.co.uk/2012/05/testing-multiple-properties-with-single.html

@jonreid
Copy link
Copy Markdown
Member

jonreid commented Jun 9, 2012

I'm curious -- what does this add that can't be done by combining multiple hasProperty into an allOf?

@sandromancuso
Copy link
Copy Markdown
Author

I think that hasProperty works well when testing a single property. allOf is good for combining different matchers.

Using allOf and multiple hasProperty, in my view, give us a broken readability. Example:

assertThat(myObject, allOf(hasProperty(...), hasProperty(...)))

I think that assertThat(myObject(has(property(..), property(...)) gives a better readability. On top of that, BeanHas and BeanProperty are offering a better error message when the assertion fails.

@sandromancuso
Copy link
Copy Markdown
Author

Hi guys,

Is there anyone looking at the pull requests? It would be great to have some feedback.

Cheers,
Sandro

@scarytom
Copy link
Copy Markdown
Member

Hey Sandro,

I'm kinda looking at pull requests, although I'm concentrating on getting a release out before taking much new code in.

@mageddo
Copy link
Copy Markdown

mageddo commented May 25, 2016

Oh god, im am looking for that @scarytom @sandromancuso

@rpyaset
Copy link
Copy Markdown

rpyaset commented Aug 28, 2018

I'm curious -- what does this add that can't be done by combining multiple hasProperty into an allOf?

compile time safety

@nhojpatrick
Copy link
Copy Markdown
Member

@sandromancuso fancy rebasing this from master, as hamcrest-core and hamcrest-library have been refactored a lot and also deprecated, so that everything is just in hamcrest.

@nhojpatrick
Copy link
Copy Markdown
Member

Going to try and kick start hamcrest, so if you want to get it merged, please rebase from the branch v2.3-candidates.
Still trying to understand how has permissions to perform a release.

@nhojpatrick nhojpatrick force-pushed the master branch 2 times, most recently from 9bc653b to e9f7fc8 Compare February 13, 2022 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

No open projects
Status: Awaiting rebase

Development

Successfully merging this pull request may close these issues.

6 participants